$(document).ready(function() {
    adjustImgs();
})

function adjustImgs() {
    $('.cutimg').each(function() {
        var self = $(this);
        var img = new Image();
        img.src = self.find('img').attr('src');
        img.addEventListener('load', function() {
            var imgWidth = img.width;
            var imgHeight = img.height;

            if ((imgWidth / imgHeight) >= (self.width() / self.height())) {
                self.find('img').css({ "width": "100%", "height": "auto" });
            } else {
                self.find('img').css({ "width": "auto", "height": "100%" });
            }
        }, false);
    })
    $('.fillimg').each(function() {
        var self = $(this);
        var img = new Image();
        img.src = self.find('img').attr('src');
        img.addEventListener('load', function() {
            var imgWidth = img.width;
            var imgHeight = img.height;

            if ((imgWidth / imgHeight) >= (self.width() / self.height())) {
                self.find('img').css({ "width": "auto", "height": "100%" });
            } else {
                self.find('img').css({ "width": "100%", "height": "auto" });
            }
        }, false);
    })
}

function msg(msg) {
    layer.open({
        content: msg,
        skin: 'msg',
        time: 3
    });
}

function remind(msg, callback) {
    layer.open({
        content: msg,
        btn: '确定',
        yes: function(index) {
            if (callback != null) {
                callback();
            }
            layer.close(index);
        }
    });
}

function confirm(msg, confirmText, func) {
    layer.open({
        content: msg,
        btn: [confirmText, '取消'],
        yes: function(index) {
            func();
            layer.close(index);
        }
    });
}

function loading() {
    layer.open({ type: 2 });
}

function endLoading() {
    layer.closeAll();
}